----------------------------------Spell Variables--------------------------------------
SPELL.m_iSpellID = 80121 -- Whatever value you want as long as it doesn't override any other spells' IDs.
SPELL.m_iRange = 240
SPELL.m_sName = "Soulburn"
SPELL.m_sToolTip =	[[Todo:Tooltip]]
SPELL.m_sIcon = "devin/blackbetty/spells/warrior/soulburn.jpg"
SPELL.m_iCoolDown = 12
SPELL.m_iManaCost = 30
SPELL.m_bRequiresTarget = true
SPELL.m_iSpellType = SPELLTYPE_SLOW
SPELL.m_bRecastWhileCasting = false
---------------------------------------------------------------------------------------

function SPELL:Cast( pl, target )

	timer.Simple(0.1, function()
		pl:SetNWBool("Casting", false) 
		pl:SetNWBool("Casted", false)
	end)
	
	local range = self.m_iRange
	
	print("Casted "..self.m_sName.."!")
		
	if(target && target:IsValid() && target != pl) then
		local dmginfo_im = DamageInfo()
			dmginfo_im:SetDamage( 2 ) 
			dmginfo_im:SetDamageType( DMG_ENERGYBEAM )
			dmginfo_im:SetAttacker( pl ) 
			dmginfo_im:SetDamageForce( Vector( 0, 0, 1000 ) ) 
		target:TakeDamageInfo( dmginfo_im ) 	
		pl:DoAnimationEvent(ACT_HL2MP_GESTURE_RANGE_ATTACK_MELEE2)
		pl:EmitSound("devin/blackbetty/weapons/SoulstoneResurrection.wav", 100, 100+math.random(-10,10))
		ParticleEffectAttach( "fire_hands_instacast", PATTACH_POINT_FOLLOW, pl, pl:LookupAttachment("anim_attachment_RH"))
			timer.Simple(0.15, function()
				if(pl:GetPos():Distance(target:GetPos()) < range)then
					ParticleEffect( "impact_firebig", target:GetPos() + Vector(0, 0, 64) + (target:GetAngles():Forward()*24), Angle(0,0,0), pl )
					if(timer.Exists("soulburn_on_"..target:EntIndex()..""))then
						timer.Destroy("soulburn_on_"..target:EntIndex().."")
					end
					timer.Create("soulburn_on_"..target:EntIndex().."", 1, 5, function() 
						if(target:Health() <= 0) then 
							timer.Destroy("soulburn_on_"..target:EntIndex().."")  
						else
							target:EmitSound("devin/blackbetty/weapons/castsounds/ShadowCast.wav", 150, 100+math.random(-10,10))
							local dmginfo_im = DamageInfo()
								dmginfo_im:SetDamage( 3 ) 
								dmginfo_im:SetDamageType( DMG_ENERGYBEAM )
								dmginfo_im:SetAttacker( pl ) 
								dmginfo_im:SetDamageForce( Vector( 0, 0, 1000 ) ) 
							target:TakeDamageInfo( dmginfo_im ) 	
							ParticleEffect( "impact_firesmall", target:GetPos() + Vector(0, 0, 32), Angle(0,0,0), pl )
							pl:EmitSound("devin/blackbetty/weapons/hit/Immolate.wav", 35, 100+math.random(10,30))
						end
					end)
					timer.Simple(5, function() 
						target:EmitSound("devin/blackbetty/weapons/Exorcism.wav", 150, 100+math.random(-10,10))
						target.Speed = true	
						target.SpeedMod = -1
						target.SpeedModDuration = 2
						target.SpeedType = "Charge"
					end)
				end
			end)
		timer.Simple(0.25, function()
			pl:SetNWBool("Casting", false)
			pl:SetNWBool("Casted", false)
		end)
	end
end




